package com.xinghai.system.service.impl;

import java.util.List;
import com.xinghai.common.utils.DateUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import com.xinghai.system.mapper.DingDeptMapper;
import com.xinghai.system.domain.DingDept;
import com.xinghai.system.service.IDingDeptService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 钉钉组织-部门Service业务层处理
 * 
 * @author xinghai
 * @date 2024-07-23
 */
@Service
public class DingDeptServiceImpl extends ServiceImpl<DingDeptMapper, DingDept> implements IDingDeptService
{
    @Autowired
    private DingDeptMapper dingDeptMapper;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    /**
     * 查询钉钉组织-部门
     * 
     * @param id 钉钉组织-部门主键
     * @return 钉钉组织-部门
     */
    @Override
    public DingDept getInfo(Long id)
    {
        return dingDeptMapper.getInfo(id);
    }

    /**
     * 查询钉钉组织-部门列表
     * 
     * @param dingDept 钉钉组织-部门
     * @return 钉钉组织-部门
     */
    @Override
    public List<DingDept> list(DingDept dingDept)
    {
            dingDept.setDelFlag("0");
        return dingDeptMapper.list(dingDept);
    }

    /**
     * 新增钉钉组织-部门
     * 
     * @param dingDept 钉钉组织-部门
     * @return 结果
     */
    @Override
    public int insert(DingDept dingDept)
    {
        dingDept.setCreateTime(DateUtils.getNowDate());
        return dingDeptMapper.insert(dingDept);
    }
    /**
     * 批量新增钉钉组织-部门
     *
     * @param dingDeptList 钉钉组织-部门
     * @return 结果
     */
    @Override
    public int insertBatch(List<DingDept> dingDeptList)
    {
        return dingDeptMapper.insertBatch(dingDeptList);
    }
    /**
     * 修改钉钉组织-部门
     * 
     * @param dingDept 钉钉组织-部门
     * @return 结果
     */
    @Override
    public int update(DingDept dingDept)
    {
        dingDept.setUpdateTime(DateUtils.getNowDate());
        return dingDeptMapper.update(dingDept);
    }

    /**
     * 批量删除钉钉组织-部门
     * 
     * @param ids 需要删除的钉钉组织-部门主键
     * @return 结果
     */
    @Override
    public int deleteBatch(Long[] ids)
    {
        return dingDeptMapper.deleteBatch(ids);
    }

    /**
     * 删除钉钉组织-部门信息
     * 
     * @param id 钉钉组织-部门主键
     * @return 结果
     */
    @Override
    public int delete(Long id)
    {
        return dingDeptMapper.delete(id);
    }

    /**
     * 导入钉钉组织-部门信息
     *
     * @param list 钉钉组织-部门信息集合
     * @return 结果
     */
    @Override
    @Transactional
    public boolean importData(List<DingDept> list){
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        try {
            DingDeptMapper dingDeptMapper = sqlSession.getMapper(DingDeptMapper.class);
            list.stream().forEach(item -> dingDeptMapper.insert(item));
            // 提交数据
            sqlSession.commit();
            sqlSession.rollback();
        } catch (Exception e) {
            sqlSession.rollback();
            return false;
        } finally {
            sqlSession.close();
        }
        return true;
    }
}
